package com.oren.webservice.service.imp;

import com.alibaba.fastjson.JSONObject;
import com.oren.system.DataUtil;
import com.oren.webservice.ReturnObject;
import com.oren.webservice.service.ResfulTest;

/**
 * @author oren
 * @time 2018/1/16 20:49
 * @description
 * @Since jdk1.7
 */
//@Component
public class ResfulTestImp implements ResfulTest {

    @Override
    public int createZone(String json) {
        JSONObject jsonObject= JSONObject.parseObject(json);
        ReturnObject returnObject= JSONObject.toJavaObject(jsonObject, ReturnObject.class);
        System.out.println("---------调用的接口名称为createZone-（创建区域）-------------");
        System.out.println("区域名称的值为:"+returnObject.getName());
        System.out.println("ips的值为:"+returnObject.getIps());
        int k= DataUtil.getRandom();
        System.out.println("返回的值为："+k);
        return k;
    }

    @Override
    public int updateZone(String json) {
        JSONObject jsonObject= JSONObject.parseObject(json);
        ReturnObject returnObject= JSONObject.toJavaObject(jsonObject, ReturnObject.class);
        System.out.println("---------调用的接口名称为updateZone-（修改区域）-------------");
        System.out.println("zoneId的值为:"+returnObject.getZoneId());
        System.out.println("区域名称的值为:"+returnObject.getName());
        System.out.println("ips的值为:"+returnObject.getIps());
        System.out.println("返回的值为："+0);
        return 0;
    }

    @Override
    public int deleteZone(String json) {
        JSONObject jsonObject= JSONObject.parseObject(json);
        ReturnObject returnObject= JSONObject.toJavaObject(jsonObject, ReturnObject.class);
        System.out.println("---------调用的接口名称为deleteZone--（删除区域）------------");
        System.out.println("zoneId的值为:"+returnObject.getZoneId());
        System.out.println("返回的值为："+0);
        return 0;
    }

    @Override
    public int createUser(String json) {
        JSONObject jsonObject= JSONObject.parseObject(json);
        ReturnObject returnObject= JSONObject.toJavaObject(jsonObject, ReturnObject.class);
        System.out.println("---------调用的接口名称为createUser--（创建用户）------------");
        System.out.println("用户名称的值为:"+returnObject.getName());
        System.out.println("is的值为:"+returnObject.getIds());
        int k= DataUtil.getRandom();
        System.out.println("返回的值为："+k);
        return k;
    }

    @Override
    public int updateUser(String json) {
        JSONObject jsonObject= JSONObject.parseObject(json);
        ReturnObject returnObject= JSONObject.toJavaObject(jsonObject, ReturnObject.class);
        System.out.println("---------调用的接口名称为updateUser--（修改用户）------------");
        System.out.println("userId的值为:"+returnObject.getUserId());
        System.out.println("用户名称的值为:"+returnObject.getName());
        System.out.println("ids的值为:"+returnObject.getIds());
        System.out.println("返回的值为："+0);
        return 0;
    }

    @Override
    public int deleteUser(String json) {
        JSONObject jsonObject= JSONObject.parseObject(json);
        ReturnObject returnObject= JSONObject.toJavaObject(jsonObject, ReturnObject.class);
        System.out.println("---------调用的接口名称为deleteUser--（删除用户）------------");
        System.out.println("userId的值为:"+returnObject.getUserId());
        System.out.println("返回的值为："+0);
        return 0;
    }

    @Override
    public int createPolicy(String json)throws Exception {
        /*String strGBK = URLEncoder.encode(json, "GBK");
        System.out.println(strGBK);
        String strUTF8 = URLDecoder.decode(json, "UTF-8");
        System.out.println(strUTF8);*/
        JSONObject jsonObject= JSONObject.parseObject(json);
        System.out.println(jsonObject.toString());
        ReturnObject returnObject= JSONObject.toJavaObject(jsonObject, ReturnObject.class);
        System.out.println("---------调用的接口名称为createPolicy--（创建策略）------------");
        System.out.println("策略name的值为:"+returnObject.getName());
        int k= DataUtil.getRandom();
        System.out.println("返回的值为："+k);
        return k;
    }

    @Override
    public int deletePolicy(String json) {
        JSONObject jsonObject= JSONObject.parseObject(json);
        ReturnObject returnObject= JSONObject.toJavaObject(jsonObject, ReturnObject.class);
        System.out.println("---------调用的接口名称为deletePolicy--（删除策略）------------");
        System.out.println("策略policyId的值为:"+returnObject.getPolicyId());
        System.out.println("返回的值为："+0);
        return 0;
    }

    @Override
    public int addRule(String json) {
        JSONObject jsonObject= JSONObject.parseObject(json);
        System.out.println(jsonObject.toString());
        ReturnObject returnObject= JSONObject.toJavaObject(jsonObject, ReturnObject.class);
        System.out.println("---------调用的接口名称为addRule-（添加规则）-------------");
        System.out.println("策略policyId的值为:"+returnObject.getPolicyId());
        System.out.println("paramMask:"+returnObject.getCond().getParamMask());
        System.out.println("outerBeginIP:"+returnObject.getCond().getOuterBeginIP());
        System.out.println("outerIPMask:"+returnObject.getCond().getOuterIPMask());
        System.out.println("outerBeginPort:"+returnObject.getCond().getOuterBeginPort());
        System.out.println("outerEndPort:"+returnObject.getCond().getOuterEndPort());
        System.out.println("protocol:"+returnObject.getCond().getProtocol());
        System.out.println("appID:"+returnObject.getCond().getAppID());
        System.out.println("subAppID:"+returnObject.getCond().getSubAppID());
        System.out.println("userId:"+returnObject.getCond().getUserId());
        System.out.println("zoneId:"+returnObject.getCond().getZoneId());
        System.out.println("netId:"+returnObject.getCond().getNetId());
        System.out.println("domain:"+returnObject.getCond().getDomain());
        System.out.println("url:"+returnObject.getCond().getUrl());
        System.out.println("zoneId:"+returnObject.getCond().getZoneId());
        System.out.println("优先级priority:"+returnObject.getPriority());
        if(returnObject.getAction().getOperType()==1){
            System.out.println("操作类型为封堵");
        }else if(returnObject.getAction().getOperType()==2){
            System.out.println("操作类型为允许");
        }else {
            System.out.println("操作类型为限速");
        }
        System.out.println("上行速率upRate:"+returnObject.getAction().getUpRate());
        System.out.println("下行速率dnRate:"+returnObject.getAction().getDnRate());
        int k= DataUtil.getRandom();
        System.out.println("返回的值为："+k);
        return k;
    }

    @Override
    public int removeRule(String json) {
        JSONObject jsonObject= JSONObject.parseObject(json);
        ReturnObject returnObject= JSONObject.toJavaObject(jsonObject, ReturnObject.class);
        System.out.println("---------调用的接口名称为removeRule-（移除规则）-------------");
        System.out.println("策略policyId的值为:"+returnObject.getPolicyId());
        System.out.println("ruleId的值为:"+returnObject.getRuleId());
        System.out.println("返回的值为："+0);
        return 0;
    }

    @Override
    public int clearRule(String json) {
        JSONObject jsonObject= JSONObject.parseObject(json);
        ReturnObject returnObject= JSONObject.toJavaObject(jsonObject, ReturnObject.class);
        System.out.println("---------调用的接口名称为removeRule-（清空规则）-------------");
        System.out.println("策略policyId的值为:"+returnObject.getPolicyId());
        System.out.println("返回的值为："+0);
        return 0;
    }

    @Override
    public int setZonePolicy(String json) {
        JSONObject jsonObject= JSONObject.parseObject(json);
        ReturnObject returnObject= JSONObject.toJavaObject(jsonObject, ReturnObject.class);
        System.out.println("---------调用的接口名称为setZonePolicy--（绑定区域策略）------------");
        System.out.println("zoneId的值为:"+returnObject.getZoneId());
        System.out.println("policyId的值为:"+returnObject.getPolicyId());
        System.out.println("返回的值为："+0);
        return 0;
    }

    @Override
    public int setUserPolicy(String json) {
        JSONObject jsonObject= JSONObject.parseObject(json);
        ReturnObject returnObject= JSONObject.toJavaObject(jsonObject, ReturnObject.class);
        System.out.println("---------调用的接口名称为setUserPolicy--（绑定用户策略）------------");
        System.out.println("userId的值为:"+returnObject.getUserId());
        System.out.println("policyId的值为:"+returnObject.getPolicyId());
        System.out.println("返回的值为："+0);
        return 0;
    }

    @Override
    public int setGlobalPolicy(String json) {
        JSONObject jsonObject= JSONObject.parseObject(json);
        ReturnObject returnObject= JSONObject.toJavaObject(jsonObject, ReturnObject.class);
        System.out.println("---------调用的接口名称为setGlobalPolicy--（绑定全局策略）------------");
        System.out.println("policyId的值为:"+returnObject.getPolicyId());
        System.out.println("返回的值为："+0);
        return 0;
    }

    @Override
    public int setPrivilegePolicy(String json) {
        JSONObject jsonObject= JSONObject.parseObject(json);
        ReturnObject returnObject= JSONObject.toJavaObject(jsonObject, ReturnObject.class);
        System.out.println("---------调用的接口名称为setPrivilegePolicy--（绑定特权策略）------------");
        System.out.println("policyId的值为:"+returnObject.getPolicyId());
        System.out.println("返回的值为："+0);
        return 0;
    }

    @Override
    public int clear(String json) {
        System.out.println("---------调用的接口名称为clear,清空所有配置--------------");
        System.out.println("返回的值为："+0);
        return 0;
    }


  /*  public String message(String json) throws UnsupportedEncodingException {
        String result="";
        result= new String(json.getBytes(),"UTF-8");
        System.out.println("json的值为:"+result);
       // System.out.println("age的值为："+age);
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("value",0);
        return 0;
    }

    @Override
    public JSONObject message1(String testParam) {
        String result="";
       // System.out.println("policyId的值为:"+policyId);
        System.out.println("testParam的值为:"+testParam);
     //   System.out.println("action的值为:"+action);
        // System.out.println("age的值为："+age);
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("testParam的值为：",testParam);
        //jsonObject.put("policyId的值为：",policyId);
       // jsonObject.put("action的值为：",action);
        return jsonObject;
    }*/


}
